package com.elegantmall.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.elegantmall.pojo.OrderPojo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;


@Mapper
@Repository
public interface OrderDao extends BaseMapper<OrderPojo> {
    // 插入订单
    @Insert("INSERT INTO orders(order_id, goods_id, seller_name, number) " +
            "VALUES(#{orderId}, #{goodsId}, #{sellerName}, #{number})")
    @Options(useGeneratedKeys = true, keyProperty = "order_id") // 关键配置
    int insertOrder(OrderPojo order);

    // 根据订单ID删除订单
    @Delete("DELETE FROM orders WHERE order_id = #{order_id}")
    int deleteById(@Param("order_id") String order_id);

    // 根据订单ID查询订单
    @Select("SELECT order_id, goods_id, seller_name, number FROM orders WHERE order_id = #{order_id}")
    OrderPojo selectById(@Param("order_id") String order_id);

    // 根据商品ID查询订单列表
    @Select("SELECT order_id, goods_id, seller_name, number FROM orders WHERE goods_id = #{goods_id}")
    List<OrderPojo> selectByGoodsId(@Param("goods_id") String goods_id);

    // 根据卖家名称查询订单列表（改为String类型）
    @Select("SELECT order_id, goods_id, seller_name, number FROM orders WHERE seller_name = #{seller_name}")
    List<OrderPojo> selectBySellerName(@Param("seller_name") String seller_name);

    // 动态更新订单信息
    /*@Update("<script>" +
            "UPDATE orders " +
            "<set>" +
            "<if test='goods_id != null'>goods_id = #{goods_id},</if>" +
            "<if test='seller_name != null'>seller_name = #{seller_name},</if>" +
            "<if test='number != null'>number = #{number},</if>" +
            "</set>" +
            "WHERE order_id = #{order_id}" +
            "</script>")
    int updateOrder(OrderPojo order);*/
}